<template lang="html">
    <div class="box">
          <div class="header">
                <el-tabs v-model="activeName" @tab-click="switchTabBar()">
                  <el-tab-pane label="分享奖励" name="1"></el-tab-pane>
                  <el-tab-pane label="推荐奖励" name="2"></el-tab-pane>
                  <el-tab-pane label="停驶奖励" name="3"></el-tab-pane>
                </el-tabs>
          </div>

          <div class="body">
                <el-form class="filterCondition demo-form-inline" ref="form"  :inline="true" label-width="80px">
                    <el-input :placeholder="activeName==1 ? '请输入推荐者' : activeName==2 ? '请输入推荐者/维修厂/运营商名称':'车主姓名'" v-model="keyword" style="width: 420px;">
                      <el-button slot="append" style="width: 120px;" @click="switchTab()">搜索</el-button>
                    </el-input>
                    <el-form-item label="时间段" style="margin-bottom: 0;width: 520px;">
                      <el-date-picker v-model="intervalTime" type="daterange" align="right" unlink-panels range-separator="-"
                        start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"
                        value-format="yyyy-MM-dd HH:mm:ss" >
                      </el-date-picker>
                    </el-form-item>
                </el-form>
                <!--  -->
                <div class="table_box" v-show="activeName==1">
                    <el-table :data="tableData.list" style="width: 100%">
                        <el-table-column prop="share_name" align="center" label="推荐者" >
                              <!-- <template lang="html" slot-scope="scope">
                                  <el-popover trigger="hover" placement="top">
                                      <p>姓名: {{ scope.row.share_name }}</p>
                                      <div slot="reference" class="name-wrapper">
                                        <el-tag size="medium">{{ scope.row.share_name }}</el-tag>
                                      </div>
                                  </el-popover>
                              </template> -->
                        </el-table-column>
                        <el-table-column  prop="refund_price"  align="center" label="奖励金额" ></el-table-column>
                        <el-table-column  prop="user_name"  align="center" label="购买者" >
                              <!-- <template lang="html" slot-scope="scope">
                                  <el-popover trigger="hover" placement="top">
                                      <p>姓名: {{ scope.row.share_name }}</p>
                                      <div slot="reference" class="name-wrapper">
                                        <el-tag size="medium">{{ scope.row.share_name }}</el-tag>
                                      </div>
                                  </el-popover>
                              </template> -->
                        </el-table-column>
                        <el-table-column  prop="user_phone"  align="center" label="购买者电话" ></el-table-column>
                        <el-table-column  prop="card_price"  align="center" label="购卡金额" ></el-table-column>
                        <el-table-column  prop="create_time"  align="center" label="时间" ></el-table-column>
                    </el-table>
                </div>
                <div class="table_box" v-show="activeName==2">
                    <el-table :data="tableData.list" style="width: 100%">
                        <el-table-column  prop="share_name"  align="center" label="推荐者" >
                            <!-- <template lang="html" slot-scope="scope">
                                <el-popover trigger="hover" placement="top">
                                    <p>姓名: {{ scope.row.share_name }}</p>
                                    <div slot="reference" class="name-wrapper">
                                      <el-tag size="medium">{{ scope.row.share_name }}</el-tag>
                                    </div>
                                </el-popover>
                            </template> -->
                        </el-table-column>
                        <el-table-column  prop="refund_price"  align="center" label="奖励金额" ></el-table-column>
                        <el-table-column  align="center" label="类型" >
                            <template slot-scope="scope">
  <p v-if="scope.row.type == 1">维修厂</p>
  <p v-if="scope.row.type == 2">运营商</p>
</template>
                        </el-table-column>
                        <el-table-column  prop="reg_name"  align="center" label="维修厂/运营商名称" >
                            <!-- <template lang="html" slot-scope="scope">
                                <el-popover trigger="hover" placement="top">
                                    <p>姓名: {{ scope.row.share_name }}</p>
                                    <div slot="reference" class="name-wrapper">
                                      <el-tag size="medium">{{ scope.row.share_name }}</el-tag>
                                    </div>
                                </el-popover>
                            </template> -->
                        </el-table-column>
                        <el-table-column  prop="create_time"  align="center" label="时间" ></el-table-column>
                    </el-table>
                </div>
                <div class="table_box" v-show="activeName==3">
                    <el-table :data="tableData.list" style="width: 100%">
                        <el-table-column  prop="user_name"  align="center" label="车主姓名" >
                          <!-- <template lang="html" slot-scope="scope">
                                  <el-popover trigger="hover" placement="top">
                                      <p>姓名: {{ scope.row.share_name }}</p>
                                      <div slot="reference" class="name-wrapper">
                                        <el-tag size="medium">{{ scope.row.share_name }}</el-tag>
                                      </div>
                                  </el-popover>
                              </template> -->
                        </el-table-column>
                        <el-table-column  prop="plate"  align="center" label="车牌号" ></el-table-column>
                        <el-table-column  prop="car_brand"  align="center" label="车型" ></el-table-column>
                        <el-table-column  prop="policy_price"  align="center" label="保单金额" ></el-table-column>
                        <el-table-column  prop="refund_price"  align="center" label="奖励金额" ></el-table-column>
                        <el-table-column  prop="create_time"  align="center" label="时间" ></el-table-column>
                    </el-table>
                </div>

                <p  class="summary">{{tableData.total}}</p>
                <!--  -->
                <div class="page_box">
                    <el-pagination class="page" layout="prev, pager, next"
                    :current-page="currentPage"
                      @current-change="switchPage" :page-count='tableData.rows' >
                    </el-pagination>
                </div>
          </div>

    </div>
</template>

<script>
export default {
  data() {
      return {
        token: this.$store.state.user.token3,
        activeName: '1',
        currentActive:'1',
        keyword: '',
        currentPage:1,
        tableData: [],
        intervalTime: [],
      }
  },
  created () {
    this.switchTab()
  },
  methods: {
      initSetData(){
        this.keyword = ''
        this.tableData = []
        this.intervalTime = []
      },
      switchTabBar(){
          if(this.activeName == this.currentActive){
            return false;
          }else{
             this.initSetData()
             this.switchTab()
             this.currentActive = this.activeName
          }
      },
      switchTab(n=this.activeName,p=1){
        this.currentPage = p;
        var jsonData = {
          token: this.token,
          key: this.keyword,
          start_time: (this.intervalTime && this.intervalTime[0]) || '',
          end_time: (this.intervalTime && this.intervalTime[1]) || '',
          page: p
        }
        switch (n) {
          case '1': //分享奖励
            this.$http3.userShareList(jsonData)
            .then(this.resultFn())
          break;
        case '2':    //推荐
          this.$http3.userRecomList(jsonData)
            .then(this.resultFn())
          break;
        case '3':
          this.$http3.userLayOffList(jsonData)
            .then(this.resultFn())
          break;
      }

    },
    resultFn () {
      return function (res) {
        if (res) {
          this.tableData =
            res.data.code === 1 ?
              this.tableData = res.data.data : [];
        }
      }.bind(this)
    },

    switchPage (e) {
      this.switchTab(this.activeName, e)
    }
  }
}
</script>

<style lang="css" scoped>
@import "../../../my-style/app.css";
/deep/ .el-input-group__append,
.el-input-group__prepend {
  background-color: #3498e9;
  border: none;
  color: white;
}
.page_box {
  text-align: center;
}
</style>
